package cn.zahou.SJR.druid;

import com.alibaba.druid.pool.DruidDataSourceFactory;

import javax.sql.DataSource;
import java.io.InputStream;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.Properties;
@SuppressWarnings("ALL")
public class MySQL_druid_pool {
    public static void main(String[] args) throws Exception {
//        1.导入jar包
//            2.定义配置文件
//        3.加载配置文件
    Properties props = new Properties();
    InputStream IS=MySQL_druid_pool.class.getClassLoader().getResourceAsStream("druid.properties");
    props.load(IS);
//    4.获取连接池对象
    DataSource ds= DruidDataSourceFactory.createDataSource(props);
    Connection connection=ds.getConnection();
    PreparedStatement pstmt=null;
    ResultSet rs=null;
        String sql = "select  * from emp";
        pstmt=connection.prepareStatement(sql);
//        处理select查询操纵
        rs=pstmt.executeQuery();
        while (rs.next()){
            System.out.printf("%3s\t%.2f\n",rs.getString("name"),rs.getDouble("salary"));
        }
        rs.close();
        pstmt.close();
        connection.close();
    }
}
